<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Menu extends Model {
	var $data;
	var $var;

    function Menu()
    {
        // Call the Model constructor
        parent::Model();
    }
    
    function isExists($id){
	if($this->db->where('id', $id)->from('menu')->count_all_results() > 0)
		return TRUE;
	else
		return FALSE;
    }
    
    function get ($pid = 0, $cat = 0)
    {
    	$menu = array();
	//$this->db->select('id, cat, title, type, desc, show, order');
	$this->db->order_by('order','asc');
	$this->db->where('cat', $cat, 'show', '1'); 
	$q = $this->db->get('menu');
	if ($q -> num_rows() > 0) {
		foreach ($q -> result() as $row){
			$row -> subMenu = $this -> get($pid,$row->id);
			if($row->id == $pid)
				$this->catInfo = $row;
			$menu[] = $row;
		}
		return $menu;
	}
		
    }
    
    function get_entry ($id)
    {
	$q = $this->db->where('id',$id)->get('menu');
	return $q -> result();
    }
    
    function insert_entry()
    {
        $this->db->insert('menu', $this->data);
    }

    function update_entry()
    {
	$this->db->where($this->var);
	$this->db->update('menu',  $this->data);
    }
    
    function remove_entry($id)
    {
	$this->db->where('mid',$id)->delete('pages');
    	
	$q = $this->db->where('cat',$id)->get('menu');
	
	if ($q -> num_rows() > 0) {
		foreach ($q -> result() as $row){
			$this->remove_entry($row->id);
		}
	}
	
	if( $this->db->where('id',$id)->delete('menu') )
        {
        	return TRUE;
        } else {
        	return FALSE;
        }
    }

}
/* End of file page.php */
/* Location: ./system/application/language/models/page.php */
